package com.bbt.dormassistant.controller;

import com.bbt.dormassistant.entity.Questionnaire;
import com.bbt.dormassistant.service.QuestionnaireService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


@Api(tags = "问卷接口")
@RestController
@RequestMapping("/questionnaire")
public class QuestionnaireController {

    @Autowired
    private QuestionnaireService questionnaireService;


    @ApiOperation(value = "获取所有查询问卷")
    @GetMapping("/findAll")
    public Map findAll(){
        Map<String,Object> map = new HashMap<>();
        map.put("questionnaires",questionnaireService.findAll());
        return map;
    }


    @ApiOperation(value = "获取用户的问卷")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "string")
    })
    @GetMapping("/findByUserId")
    public Map findByUserId(@RequestParam String userId){
        Map<String,Object> map = new HashMap<>();
        map.put("questionnaire",questionnaireService.findByUserId(userId));
        return map;
    }



    @ApiOperation(value = "根据userId,修改问卷")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "questionnaire", value = "问卷", required = true, dataType = "object")
    })
    @PostMapping(path = "/modifyByUserId", produces = "application/json;charset=UTF-8")
    public Map modifyByUserId(@RequestBody Questionnaire questionnaire){
        Map<String,Object> map = new HashMap<>();
        map.put("success",questionnaireService.modifyByUserId(questionnaire));
        return map;
    }
}
